package com.jiazhong.example.project.bookstore.backend.controller;

import com.jiazhong.example.project.bookstore.backend.service.DiscountService;
import com.jiazhong.example.project.bookstore.commons.bean.Discount;
import com.jiazhong.example.project.bookstore.commons.util.JsonResult;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/discount")
@Slf4j
public class DiscountController {
    @Resource
    private DiscountService discountService;


    @PostMapping("/save_update")
    public JsonResult saveOrUpdate(Discount discount, HttpServletRequest request) {
        log.info("saveOrUpdate discount:{}", discount);
        return discountService.saveOrUpdateDiscount(discount, request.getHeader("token"));
    }

    @GetMapping("/{bookId}")
    public JsonResult findDiscountRateByBookId(@PathVariable("bookId") String bookId) {
        return discountService.findDiscountByBookId(bookId);
    }
}
